#ifndef _TIMERS_H_
#define _TIMERS_H_

#include <windows.h>
#include "types/TStaticPool.h"
#include "types/types.h"

//----------------------------------------------
class CTimer
{
	friend class STimerManager;
public:
	CTimer(float fDelay, bool bLoop);
	~CTimer();

	void			start		();
	void			stop		();
	virtual void	onTimer		() = 0;
	void			setDelay	(float fDelay) { m_fDelay = fDelay; }
	int				getId		() const { return m_iId; }

protected:
	float	m_fDelay;
private:
	void			postOnTimer	();

	int		m_iId;
	bool	m_bStarted;
	bool	m_bLoop;
};

//----------------------------------------------
class STimerManager
{
	DECLARE_SINGLETON(STimerManager);
public:
	void	addTimer		(CTimer& oTimer);
	void	removeTimer		(CTimer& oTimer);
	CTimer*	getTimer		(unsigned int uiId) const;

	static VOID CALLBACK timerCallback( HWND hWnd, UINT uiMsg, UINT uiTimerId, DWORD dwTime);

private:
	static const int	ms_maxTimers = 20;

	TStaticPool<CTimer*, ms_maxTimers>	m_timers;
};

#endif
